/**
 * Copyright 2013 Mr.Hai Mobile Developer. All rights reserved.
 * HAI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hector.meinewerk.utils.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hector.meinewerk.client.R;

/**
 * adapter cho dialog chup hinh
 * 
 * @author: HaiTC
 * @version: 1.0
 * @since: 1.0
 */
public class TakingPhotoAdapter extends BaseAdapter {

	public static final int ITEM_FROM_ALBUM = 0;//action item chon hinh
	public static final int ITEM_TAKE_PHOTO = 1;//action item chup hinh
	public static final int ITEM_DELETE = 2;//action item xoa hinh
	
	private static String[] itemsOpen = null;//mang item
	private static String[] itemsOpenDelete = null;//mang item
	
	private static Drawable listImageItem[] = null;//mang icon
	
	
	
	private String[] itemArray;//mang item

	public TakingPhotoAdapter(Context context, boolean enableDeleteItem) {
		// TODO Auto-generated constructor stub

		if (listImageItem == null) {
			listImageItem = new Drawable[3];
			listImageItem[0] = context.getResources().getDrawable(
					R.drawable.ic_from_device);
			listImageItem[1] = context.getResources().getDrawable(
					R.drawable.ic_from_camera);
			listImageItem[2] = context.getResources().getDrawable(
					R.drawable.ic_big_delete);
		}
		if (itemsOpen == null){
			itemsOpen = new String[2];
			itemsOpen[0] = context.getResources().getString(R.string.CHOOSE_FROM_PHONE);
			itemsOpen[1] = context.getResources().getString(R.string.TAKE_NEW_PHOTO);
		}
		if (itemsOpenDelete == null){
			itemsOpenDelete = new String[3];
			itemsOpenDelete[0] = context.getResources().getString(R.string.CHOOSE_FROM_PHONE);
			itemsOpenDelete[1] = context.getResources().getString(R.string.TAKE_NEW_PHOTO);
			itemsOpenDelete[2] = context.getResources().getString(R.string.DELETE_PHOTO);
		}
		if (enableDeleteItem) {
			itemArray = itemsOpenDelete;
		} else {
			itemArray = itemsOpen;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return itemArray.length;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return itemArray[arg0];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			final LayoutInflater inflater = (LayoutInflater) viewGroup
					.getContext().getSystemService(
							Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.dialog_item, null);
			
		}
		ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
		TextView text = (TextView) convertView.findViewById(R.id.title);
		icon.setImageDrawable(listImageItem[position]);
		text.setText(itemArray[position]);
		return convertView;
	}
}

